import { Tag, Space, Rate } from 'antd';
import styles from './index.less';

interface columnsProps {
  handleDetails: (value: any) => void;
  handleReply: (value: any) => void;
}

const columns = ({ handleDetails, handleReply }: columnsProps) => [
  {
    title: '内容',
    dataIndex: 'content',
  },
  {
    title: '评级',
    dataIndex: 'rate',
    render: (_text: any, record: any) => {
      switch (record.rate) {
        case 1:
          return <Tag color="green">好评</Tag>;
        case 2:
          return <Tag color="blue">中评</Tag>;
        case 3:
          return <Tag color="red">差评</Tag>;
        default:
          return record.rate;
      }
    },
  },
  {
    title: '星级',
    dataIndex: 'star',
  },
  {
    title: '回复',
    dataIndex: 'reply',
    render: (_text: any, record: any) => {
      return <Rate disabled defaultValue={record.reply} />;
    },
  },
  {
    title: '评价时间',
    dataIndex: 'created_at',
  },
  {
    title: '操作',
    key: 'action',
    render: (text: any, record: any) => (
      <Space size="middle">
        <span className={styles.editBtn} onClick={() => handleDetails(record)}>
          详情
        </span>
        <span className={styles.editBtn} onClick={() => handleReply(record)}>
          回复
        </span>
      </Space>
    ),
  },
];

export default columns;
